package com.example.module_motorcircle.motor_circle.adapter

import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.example.module_motorcircle.InformationFragment
import com.example.module_motorcircle.post.PostListFragment
import com.example.module_motorcircle.motor_circle.model.MotorCircleNavigationItem

/**
 * @author yaotianxue
 * @description
 * @date 2025/2/11
 */
class MotorCirclePagerAdapter(private val item:List<MotorCircleNavigationItem>, fm:Fragment):FragmentStateAdapter(fm){
    override fun getItemCount(): Int {
        return item.size
    }

    override fun getItemId(position: Int): Long {
        return item[position].navigationId.toLong()
    }

    override fun createFragment(position: Int): Fragment {
        val navigation = item[position]
        return when(navigation.type){
            //热门
            1-> PostListFragment.newInstance(category = 0)
            //帖子
            2-> PostListFragment.newInstance(category = 2)
            //资讯
            3-> InformationFragment.newInstance()
            //关注
            4-> PostListFragment.newInstance(category = 4)
            //其他
            else-> PostListFragment.newInstance(category = 0)



        }
    }
}